﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataAccess
{
    public class PhanCongGiangDay_GV
    {
        private string _maGV;
        public string MaGV
        {
            get { return _maGV; }
            set { _maGV = value; }
        }

        private string _maMH;
        public string MaMH
        {
            get { return _maMH; }
            set { _maMH = value; }
        }
        private string _tenMH;

        public string TenMH
        {
            get { return _tenMH; }
            set { _tenMH = value; }
        }

        private int _hocKy;
        public int HocKy
        {
            get { return _hocKy; }
            set { _hocKy = value; }
        }

        private string _namHoc;
        public string NamHoc
        {
            get { return _namHoc; }
            set { _namHoc = value; }
        }
        public PhanCongGiangDay_GV() { }

        public PhanCongGiangDay_GV(string gv, string mh,string  ten,int hk,string nh)
        {
            MaGV = gv;
            MaMH = mh;
            TenMH=ten;
            HocKy = hk;
            NamHoc = nh;
        }

        public PhanCongGiangDay_GV(PhanCongGiangDay_GV pc)
        {
            MaGV = pc.MaGV;
            MaMH = pc.MaMH;
            TenMH=pc.TenMH;
            HocKy = pc.HocKy;
            NamHoc = pc.NamHoc;
        }
        
        public static List<PhanCongGiangDay_GV> PhancongGiangDay_LoadNamHoc_HocKy_TenMonHoc(string magv,string namhoc, int hk)
        {
               List<PhanCongGiangDay_GV> list = new List<PhanCongGiangDay_GV>();
                using (SqlConnection connec = MyConnection.MyConn())
                {
                    SqlCommand cmd = MyCommand.Command("PhanCongGiangDay_LoadNamHoc_HocKy_MonHoc", connec);
                    cmd.Parameters.Add("@MaGV", SqlDbType.VarChar, 10).Value = magv;
                    cmd.Parameters.Add("@NamHoc", SqlDbType.VarChar, 20).Value = namhoc;
                    cmd.Parameters.Add("@HocKy", SqlDbType.Int).Value = hk;
                    connec.Open();
                    using (SqlDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            PhanCongGiangDay_GV pc = GetGV(reader);
                            list.Add(pc);
                        }
                    }
                }
                return list;
        }

        private static PhanCongGiangDay_GV GetGV(SqlDataReader reader)
        {
            PhanCongGiangDay_GV pc = new PhanCongGiangDay_GV();
            pc.MaGV = reader["MaGV"].ToString();
            pc.MaMH = reader["MaMH"].ToString();
            pc.TenMH = reader["TenMH"].ToString();
            pc.HocKy = Convert.ToInt32(reader["HocKy"]);
            pc.NamHoc = reader["NamHoc"].ToString();
            return pc;
        }
    }
}
